package club.dmyang;

import org.jasypt.encryption.StringEncryptor;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.util.DigestUtils;

/**
 * Created by brss on 2018/7/18.
 */
@RunWith(SpringRunner.class)
@SpringBootTest
public class PwdGenerator {

    @Autowired
    StringEncryptor encryptor;

    /**
     * 数据库中：表user的密码生成器。这里密码为abc，得到的结果插入到数据库中即可
     */
    @Test
    public void generatorPwd() {
        String s = DigestUtils.md5DigestAsHex("520926".getBytes());
        System.out.println(s);

    }

    /**
     * 配置文件加密，把得到的结果写入到：application.properties中，如下：
     * spring.datasource.username=ENC(DL7hgQ76XxKnZOwi8ZGeng==)
     * spring.datasource.password=ENC(/2tjLkeVO645TdPy66+47Q==)
     * 注意：需要加上：ENC(XXX)
     */
    @Test
    public void getPass() {
        /*String name = encryptor.encrypt("DBusername");
        String password = encryptor.encrypt("DBpassword");*/
        String name = encryptor.encrypt("root");
        String password = encryptor.encrypt("root");
        System.out.println(name + "----------------");
        System.out.println(password + "----------------");

    }

}
